///////////////////////////////////////////////////////////////////////////////////
datum
	chemical_reaction
		var/name = null
		var/id = null
		var/result = null
		var/list/required_reagents = new/list()
		var/list/required_catalysts = new/list()

		// Both of these variables are mostly going to be used with slime cores - but if you want to, you can use them for other things
		var/atom/required_container = null // the container required for the reaction to happen
		var/required_other = 0 // an integer required for the reaction to happen

		var/result_amount = 0
		var/secondary = 0 // set to nonzero if secondary reaction
		var/list/secondary_results = list()		//additional reagents produced by the reaction
		var/requires_heating = 0

		proc
			on_reaction(var/datum/reagents/holder, var/created_volume)
				return

		//I recommend you set the result amount to the total volume of all components.
/*
		silicate
			name = "Silicate"
			id = "silicate"
			result = "silicate"
			required_reagents = list("aluminum" = 1, "silicon" = 1, "oxygen" = 1)
			result_amount = 3
*/
		stoxin
			name = "Sleep Toxin"
			id = "stoxin"
			result = "stoxin"
			required_reagents = list("chloralhydrate" = 1, "sugar" = 4)
			result_amount = 5

		sterilizine
			name = "Sterilizine"
			id = "sterilizine"
			result = "sterilizine"
			required_reagents = list("ethanol" = 1, "anti_toxin" = 1, "chlorine" = 1)
			result_amount = 3

		//cyanide
		//	name = "Cyanide"
		//	id = "cyanide"
		//	result = "cyanide"
		//	required_reagents = list("hydrogen" = 1, "carbon" = 1, "nitrogen" = 1)
		//	result_amount = 1

		thermite
			name = "Thermite"
			id = "thermite"
			result = "thermite"
			required_reagents = list("aluminum" = 1, "iron" = 1, "oxygen" = 1)
			result_amount = 3

		lexorin
			name = "Lexorin"
			id = "lexorin"
			result = "lexorin"
			required_reagents = list("plasma" = 1, "hydrogen" = 1, "nitrogen" = 1)
			result_amount = 3

		space_drugs
			name = "Space Drugs"
			id = "space_drugs"
			result = "space_drugs"
			required_reagents = list("mercury" = 1, "sugar" = 1, "lithium" = 1)
			result_amount = 3

		lube
			name = "Space Lube"
			id = "lube"
			result = "lube"
			required_reagents = list("water" = 1, "silicon" = 1, "oxygen" = 1)
			result_amount = 4

		pacid
			name = "Polytrinic acid"
			id = "pacid"
			result = "pacid"
			required_reagents = list("sacid" = 1, "chlorine" = 1, "potassium" = 1)
			result_amount = 3

		ethanoloxidation
			name = "ethanoloxidation"	//Kind of a placeholder in case someone ever changes it so that chemicals
			id = "ethanoloxidation"		//	react in the body. Also it would be silly if it didn't exist.
			result = "water"
			required_reagents = list("ethylredoxrazine" = 1, "ethanol" = 1)
			result_amount = 2

		glycerol
			name = "Glycerol"
			id = "glycerol"
			result = "glycerol"
			required_reagents = list("cornoil" = 3, "sacid" = 1)
			result_amount = 1

		/*
		smoke
			name = "Smoke"
			id = "smoke"
			result = null
			required_reagents = list("potassium" = 1, "sugar" = 1, "phosphorus" = 1 )
			result_amount = null
			secondary = 1
			on_reaction(var/datum/reagents/holder, var/created_volume)
				var/location = get_turf(holder.my_atom)
				var/datum/effect/system/bad_smoke_spread/S = new /datum/effect/system/bad_smoke_spread
				S.attach(location)
				S.set_up(10, 0, location)
				playsound(location, 'sound/effects/smoke.ogg', 50, 1, -3)
				spawn(0)
					S.start()
					sleep(10)
					S.start()
					sleep(10)
					S.start()
					sleep(10)
					S.start()
					sleep(10)
					S.start()
				holder.clear_reagents()
				return	*/

		chemsmoke
			name = "Chemsmoke"
			id = "chemsmoke"
			result = null
			required_reagents = list("potassium" = 1, "sugar" = 1, "phosphorus" = 1)
			result_amount = null
			secondary = 1
			on_reaction(var/datum/reagents/holder, var/created_volume)
				var/location = get_turf(holder.my_atom)
				var/datum/effect/effect/system/chem_smoke_spread/S = new /datum/effect/effect/system/chem_smoke_spread
				S.attach(location)
				S.set_up(holder, 10, 0, location)
				playsound(location, 'sound/effects/smoke.ogg', 50, 1, -3)
				spawn(0)
					S.start()
					sleep(10)
					S.start()
				holder.clear_reagents()
				return

		plasmasolidification
			name = "Solid Plasma"
			id = "solidplasma"
			result = null
			required_reagents = list("iron" = 5, "frostoil" = 5, "plasma" = 20)
			result_amount = 1
			on_reaction(var/datum/reagents/holder, var/created_volume)
				var/location = get_turf(holder.my_atom)
				new /obj/item/stack/sheet/mineral/plasma(location)
				return

		capsaicincondensation
			name = "Capsaicincondensation"
			id = "capsaicincondensation"
			result = "condensedcapsaicin"
			required_reagents = list("capsaicin" = 1, "ethanol" = 5)
			result_amount = 5

		virus_food
			name = "Virus Food"
			id = "virusfood"
			result = "virusfood"
			required_reagents = list("water" = 5, "milk" = 5, "oxygen" = 5)
			result_amount = 15

		mix_virus
			name = "Mix Virus"
			id = "mixvirus"
			result = "blood"
			required_reagents = list("virusfood" = 5)
			required_catalysts = list("blood")
			var/level = 2

			on_reaction(var/datum/reagents/holder, var/created_volume)

				var/datum/reagent/blood/B = locate(/datum/reagent/blood) in holder.reagent_list
				if(B && B.data)
					var/datum/disease/advance/D = locate(/datum/disease/advance) in B.data["viruses"]
					if(D)
						D.Evolve(level - rand(0, 1))


			mix_virus_2

				name = "Mix Virus 2"
				id = "mixvirus2"
				required_reagents = list("mutagen" = 5)
				level = 4

			mix_virus_3

				name = "Mix Virus 3"
				id = "mixvirus3"
				required_reagents = list("plasma" = 5)
				level = 6

			rem_virus

				name = "Devolve Virus"
				id = "remvirus"
				required_reagents = list("synaptizine" = 5)

				on_reaction(var/datum/reagents/holder, var/created_volume)

					var/datum/reagent/blood/B = locate(/datum/reagent/blood) in holder.reagent_list
					if(B && B.data)
						var/datum/disease/advance/D = locate(/datum/disease/advance) in B.data["viruses"]
						if(D)
							D.Devolve()



///////////////////////////////////////////////////////////////////////////////////

// foam and foam precursor

		surfactant
			name = "Foam surfactant"
			id = "foam surfactant"
			result = "fluorosurfactant"
			required_reagents = list("fluorine" = 2, "carbon" = 2, "sacid" = 1)
			result_amount = 5


		foam
			name = "Foam"
			id = "foam"
			result = null
			required_reagents = list("fluorosurfactant" = 1, "water" = 1)
			result_amount = 2

			on_reaction(var/datum/reagents/holder, var/created_volume)


				var/location = get_turf(holder.my_atom)
				for(var/mob/M in viewers(5, location))
					M << "\red The solution violently bubbles!"

				location = get_turf(holder.my_atom)

				for(var/mob/M in viewers(5, location))
					M << "\red The solution spews out foam!"

				//world << "Holder volume is [holder.total_volume]"
				//for(var/datum/reagent/R in holder.reagent_list)
				//	world << "[R.name] = [R.volume]"

				var/datum/effect/effect/system/foam_spread/s = new()
				s.set_up(created_volume, location, holder, 0)
				s.start()
				holder.clear_reagents()
				return

		metalfoam
			name = "Metal Foam"
			id = "metalfoam"
			result = null
			required_reagents = list("aluminum" = 3, "foaming_agent" = 1, "pacid" = 1)
			result_amount = 5

			on_reaction(var/datum/reagents/holder, var/created_volume)


				var/location = get_turf(holder.my_atom)

				for(var/mob/M in viewers(5, location))
					M << "\red The solution spews out a metalic foam!"

				var/datum/effect/effect/system/foam_spread/s = new()
				s.set_up(created_volume, location, holder, 1)
				s.start()
				return

		ironfoam
			name = "Iron Foam"
			id = "ironlfoam"
			result = null
			required_reagents = list("iron" = 3, "foaming_agent" = 1, "pacid" = 1)
			result_amount = 5

			on_reaction(var/datum/reagents/holder, var/created_volume)


				var/location = get_turf(holder.my_atom)

				for(var/mob/M in viewers(5, location))
					M << "\red The solution spews out a metalic foam!"

				var/datum/effect/effect/system/foam_spread/s = new()
				s.set_up(created_volume, location, holder, 2)
				s.start()
				return



		foaming_agent
			name = "Foaming Agent"
			id = "foaming_agent"
			result = "foaming_agent"
			required_reagents = list("lithium" = 1, "hydrogen" = 1)
			result_amount = 1

		// Synthesizing these three chemicals is pretty complex in real life, but fuck it, it's just a game!
		ammonia
			name = "Ammonia"
			id = "ammonia"
			result = "ammonia"
			required_reagents = list("hydrogen" = 3, "nitrogen" = 1)
			result_amount = 3

		diethylamine
			name = "Diethylamine"
			id = "diethylamine"
			result = "diethylamine"
			required_reagents = list ("ammonia" = 1, "ethanol" = 1)
			result_amount = 2

		space_cleaner
			name = "Space cleaner"
			id = "cleaner"
			result = "cleaner"
			required_reagents = list("ammonia" = 1, "water" = 1, "plasma" = 1)
			result_amount = 9

		plantbgone
			name = "Plant-B-Gone"
			id = "plantbgone"
			result = "plantbgone"
			required_reagents = list("toxin" = 1, "water" = 4)
			result_amount = 5


/////////////////////////////////////OLD SLIME CORE REACTIONS ///////////////////////////////
/*
		slimepepper
			name = "Slime Condensedcapaicin"
			id = "m_condensedcapaicin"
			result = "condensedcapsaicin"
			required_reagents = list("sugar" = 1)
			result_amount = 1
			required_container = /obj/item/slime_core
			required_other = 1
		slimefrost
			name = "Slime Frost Oil"
			id = "m_frostoil"
			result = "frostoil"
			required_reagents = list("water" = 1)
			result_amount = 1
			required_container = /obj/item/slime_core
			required_other = 1
		slimeglycerol
			name = "Slime Glycerol"
			id = "m_glycerol"
			result = "glycerol"
			required_reagents = list("blood" = 1)
			result_amount = 1
			required_container = /obj/item/slime_core
			required_other = 1

		slime_explosion
			name = "Slime Explosion"
			id = "m_explosion"
			result = null
			required_reagents = list("blood" = 1)
			result_amount = 2
			required_container = /obj/item/slime_core
			required_other = 2
			on_reaction(var/datum/reagents/holder, var/created_volume)
				var/location = get_turf(holder.my_atom)
				var/datum/effect/effect/system/reagents_explosion/e = new()
				e.set_up(round (created_volume/10, 1), location, 0, 0)
				e.start()

				holder.clear_reagents()
				return
		slimejam
			name = "Slime Jam"
			id = "m_jam"
			result = "slimejelly"
			required_reagents = list("water" = 1)
			result_amount = 1
			required_container = /obj/item/slime_core
			required_other = 2
		slimesynthi
			name = "Slime Synthetic Flesh"
			id = "m_flesh"
			result = null
			required_reagents = list("sugar" = 1)
			result_amount = 1
			required_container = /obj/item/slime_core
			required_other = 2
			on_reaction(var/datum/reagents/holder, var/created_volume)
				var/location = get_turf(holder.my_atom)
				new /obj/item/weapon/reagent_containers/food/snacks/meat/syntiflesh(location)
				return

		slimeenzyme
			name = "Slime Enzyme"
			id = "m_enzyme"
			result = "enzyme"
			required_reagents = list("blood" = 1, "water" = 1)
			result_amount = 2
			required_container = /obj/item/slime_core
			required_other = 3
		slimeplasma
			name = "Slime Plasma"
			id = "m_plasma"
			result = "plasma"
			required_reagents = list("sugar" = 1, "blood" = 2)
			result_amount = 2
			required_container = /obj/item/slime_core
			required_other = 3
		slimevirus
			name = "Slime Virus"
			id = "m_virus"
			result = null
			required_reagents = list("sugar" = 1, "sacid" = 1)
			result_amount = 2
			required_container = /obj/item/slime_core
			required_other = 3
			on_reaction(var/datum/reagents/holder, var/created_volume)
				holder.clear_reagents()

				var/virus = pick(/datum/disease/advance/flu, /datum/disease/advance/cold, \
				 /datum/disease/pierrot_throat, /datum/disease/fake_gbs, \
				 /datum/disease/brainrot, /datum/disease/magnitis)


				var/datum/disease/F = new virus(0)
				var/list/data = list("viruses"= list(F))
				holder.add_reagent("blood", 20, data)

				holder.add_reagent("cyanide", rand(1,10))

				return

		slimeteleport
			name = "Slime Teleport"
			id = "m_tele"
			result = null
			required_reagents = list("pacid" = 2, "mutagen" = 2)
			required_catalysts = list("plasma" = 1)
			result_amount = 1
			required_container = /obj/item/slime_core
			required_other = 4
			on_reaction(var/datum/reagents/holder, var/created_volume)

				// Calculate new position (searches through beacons in world)
				var/obj/item/device/radio/beacon/chosen
				var/list/possible = list()
				for(var/obj/item/device/radio/beacon/W in world)
					possible += W

				if(possible.len > 0)
					chosen = pick(possible)

				if(chosen)
				// Calculate previous position for transition

					var/turf/FROM = get_turf_loc(holder.my_atom) // the turf of origin we're travelling FROM
					var/turf/TO = get_turf_loc(chosen)			 // the turf of origin we're travelling TO

					playsound(TO, 'sound/effects/phasein.ogg', 100, 1)

					var/list/flashers = list()
					for(var/mob/living/carbon/human/M in viewers(TO, null))
						if(M:eyecheck() <= 0)
							flick("e_flash", M.flash) // flash dose faggots
							flashers += M

					var/y_distance = TO.y - FROM.y
					var/x_distance = TO.x - FROM.x
					for (var/atom/movable/A in range(2, FROM )) // iterate thru list of mobs in the area
						if(istype(A, /obj/item/device/radio/beacon)) continue // don't teleport beacons because that's just insanely stupid
						if( A.anchored && !istype(A, /mob/dead/observer) ) continue // don't teleport anchored things (computers, tables, windows, grilles, etc) because this causes problems!
						// do teleport ghosts however because hell why not

						var/turf/newloc = locate(A.x + x_distance, A.y + y_distance, TO.z) // calculate the new place
						if(!A.Move(newloc)) // if the atom, for some reason, can't move, FORCE them to move! :) We try Move() first to invoke any movement-related checks the atom needs to perform after moving
							A.loc = locate(A.x + x_distance, A.y + y_distance, TO.z)

						spawn()
							if(ismob(A) && !(A in flashers)) // don't flash if we're already doing an effect
								var/mob/M = A
								if(M.client)
									var/obj/blueeffect = new /obj(src)
									blueeffect.screen_loc = "WEST,SOUTH to EAST,NORTH"
									blueeffect.icon = 'icons/effects/effects.dmi'
									blueeffect.icon_state = "shieldsparkles"
									blueeffect.layer = 17
									blueeffect.mouse_opacity = 0
									M.client.screen += blueeffect
									sleep(20)
									M.client.screen -= blueeffect
									del(blueeffect)
		slimecrit
			name = "Slime Crit"
			id = "m_tele"
			result = null
			required_reagents = list("sacid" = 1, "blood" = 1)
			required_catalysts = list("plasma" = 1)
			result_amount = 1
			required_container = /obj/item/slime_core
			required_other = 4
			on_reaction(var/datum/reagents/holder, var/created_volume)

				var/blocked = list(/mob/living/simple_animal/hostile,
					/mob/living/simple_animal/hostile/pirate,
					/mob/living/simple_animal/hostile/pirate/ranged,
					/mob/living/simple_animal/hostile/russian,
					/mob/living/simple_animal/hostile/russian/ranged,
					/mob/living/simple_animal/hostile/syndicate,
					/mob/living/simple_animal/hostile/syndicate/melee,
					/mob/living/simple_animal/hostile/syndicate/melee/space,
					/mob/living/simple_animal/hostile/syndicate/ranged,
					/mob/living/simple_animal/hostile/syndicate/ranged/space,
					/mob/living/simple_animal/hostile/alien/queen/large,
					/mob/living/simple_animal/clown
					)//exclusion list for things you don't want the reaction to create.
				var/list/critters = typesof(/mob/living/simple_animal/hostile) - blocked // list of possible hostile mobs

				playsound(get_turf_loc(holder.my_atom), 'sound/effects/phasein.ogg', 100, 1)

				for(var/mob/living/carbon/human/M in viewers(get_turf_loc(holder.my_atom), null))
					if(M:eyecheck() <= 0)
						flick("e_flash", M.flash)

				for(var/i = 1, i <= created_volume, i++)
					var/chosen = pick(critters)
					var/mob/living/simple_animal/hostile/C = new chosen
					C.loc = get_turf_loc(holder.my_atom)
					if(prob(50))
						for(var/j = 1, j <= rand(1, 3), j++)
							step(C, pick(NORTH,SOUTH,EAST,WEST))
		slimebork
			name = "Slime Bork"
			id = "m_tele"
			result = null
			required_reagents = list("sugar" = 1, "water" = 1)
			result_amount = 2
			required_container = /obj/item/slime_core
			required_other = 4
			on_reaction(var/datum/reagents/holder, var/created_volume)

				var/list/borks = typesof(/obj/item/weapon/reagent_containers/food/snacks) - /obj/item/weapon/reagent_containers/food/snacks
				// BORK BORK BORK

				playsound(get_turf_loc(holder.my_atom), 'sound/effects/phasein.ogg', 100, 1)

				for(var/mob/living/carbon/human/M in viewers(get_turf_loc(holder.my_atom), null))
					if(M:eyecheck() <= 0)
						flick("e_flash", M.flash)

				for(var/i = 1, i <= created_volume + rand(1,2), i++)
					var/chosen = pick(borks)
					var/obj/B = new chosen
					if(B)
						B.loc = get_turf_loc(holder.my_atom)
						if(prob(50))
							for(var/j = 1, j <= rand(1, 3), j++)
								step(B, pick(NORTH,SOUTH,EAST,WEST))



		slimechloral
			name = "Slime Chloral"
			id = "m_bunch"
			result = "chloralhydrate"
			required_reagents = list("blood" = 1, "water" = 2)
			result_amount = 2
			required_container = /obj/item/slime_core
			required_other = 5
		slimeretro
			name = "Slime Retro"
			id = "m_xeno"
			result = null
			required_reagents = list("sugar" = 1)
			result_amount = 1
			required_container = /obj/item/slime_core
			required_other = 5
			on_reaction(var/datum/reagents/holder, var/created_volume)
				var/datum/disease/F = new /datum/disease/dna_retrovirus(0)
				var/list/data = list("viruses"= list(F))
				holder.add_reagent("blood", 20, data)
		slimefoam
			name = "Slime Foam"
			id = "m_foam"
			result = null
			required_reagents = list("sacid" = 1)
			result_amount = 2
			required_container = /obj/item/slime_core
			required_other = 5

			on_reaction(var/datum/reagents/holder, var/created_volume)


				var/location = get_turf(holder.my_atom)
				for(var/mob/M in viewers(5, location))
					M << "\red The solution violently bubbles!"

				location = get_turf(holder.my_atom)

				for(var/mob/M in viewers(5, location))
					M << "\red The solution spews out foam!"

				//world << "Holder volume is [holder.total_volume]"
				//for(var/datum/reagent/R in holder.reagent_list)
				//	world << "[R.name] = [R.volume]"

				var/datum/effect/effect/system/foam_spread/s = new()
				s.set_up(created_volume, location, holder, 0)
				s.start()
				holder.clear_reagents()
				return
*/